import Vue from "vue";
import Router from "vue-router";
import common from "../../static/js/common.js";
Vue.use(Router);

const router = new Router({
	//mode: 'hash',
	mode: "history",
	routes: [
		{
			path: "/login",		// 登录
			component: resolve => require(["@/pages/common/login"], resolve),
			meta: { withoutAuth: true }
		},
		{
			path: "/index/echart",		// 图表大屏
			component: resolve => require(["@/pages/index/echart"], resolve),
		},
		{
			path: "/",
			redirect: { path: "/index/index" },
			component: resolve => require(["@/pages/common/layout"], resolve),
			children: [
				{
					path: "/index/index",
					component: resolve => require(["@/pages/index/index"], resolve),
					meta: { title: "大屏分析" }
				},
				{
					path: "/index/money",
					component: resolve => require(["@/pages/index/money"], resolve),
					meta: { title: "推广亏盈" }
				},
				{
					path: "/index/order",
					component: resolve => require(["@/pages/index/order"], resolve),
					meta: { title: "订单记录" }
				},
				
				{
					path: "/user/index",
					component: resolve => require(["@/pages/user/index"], resolve),
					meta: { title: "用户列表" }
				},
				{
					path: "/user/detail",
					component: resolve => require(["@/pages/user/detail"], resolve),
					meta: { title: "用户详情" }
				},
				
				
				{
					path: "/use/index",
					component: resolve => require(["@/pages/use/index"], resolve),
					meta: { title: "使用记录" }
				},
				
				
				{
					path: "/set/index",
					component: resolve => require(["@/pages/set/index"], resolve),
					meta: { title: "基本设置" }
				},{
					path: "/set/vipPrice",
					component: resolve => require(["@/pages/set/vipPrice"], resolve),
					meta: { title: "会员价格" }
				},
				{
					path: "/set/builtToken",
					component: resolve => require(["@/pages/set/builtToken"], resolve),
					meta: { title: "Token内置" }
				},
				{
					path: "/set/complaint",
					component: resolve => require(["@/pages/set/complaint"], resolve),
					meta: { title: "投诉管理" }
				},
				{
					path: "/set/version",
					component: resolve => require(["@/pages/set/version"], resolve),
					meta: { title: "版本升级" }
				},
				{
					path: "/set/admin",
					component: resolve => require(["@/pages/set/admin"], resolve),
					meta: { title: "管理员" }
				},
				{
					path: "/set/appChannel",
					component: resolve => require(["@/pages/set/appChannel"], resolve),
					meta: { title: "渠道设置" }
				},
				{
					path: "/set/payChannel",
					component: resolve => require(["@/pages/set/payChannel"], resolve),
					meta: { title: "支付配置" }
				},
				{
					path: "/set/sensitiveSords",
					component: resolve => require(["@/pages/set/sensitiveSords"], resolve),
					meta: { title: "音乐提交敏感词" }
				},
				{
					path: "/set/adsReport",
					component: resolve => require(["@/pages/set/adsReport"], resolve),
					meta: { title: "归因上报日志" }
				},
				{
					path: "/set/adsMonitor",
					component: resolve => require(["@/pages/set/adsMonitor"], resolve),
					meta: { title: "归因监测日志" }
				},
			],
		}
	]
});

router.beforeEach((to, from, next) => {
	if (to.meta.withoutAuth) {
		next();
	} else {
		if (common.isLogin()) {
			next();
		} else {
			next({ path: "/login" });
		}
	}
});

export default router;
